;(function ($) {
    /*
    * 保养评分
    * score('指派','null','1523343956628073','1481185324868002','null','http://gable-hospital.oss-cn-shanghai.aliyuncs.com/repair/1523343955371.png,http://gable-hospital.oss-cn-shanghai.aliyuncs.com/repair/1523343956271.png,')
    * */
    $.canshu = function (options, isWebsocket){
        var defaults = {};
        var opts = $.extend({}, defaults, options);

        var CLASS = 'canshu-' + Date.parse(new Date()) + '-';
        /* 添加模态框 */
        var model = $('#' + CLASS + 'modal');
        if (!model.length) {
            /* iziModal模态窗口:报修处理 */
            $('body').append('<div id="' + CLASS + 'modal" class="score" style="background:#f5f5f5;">' +
                '<div class="box-body" style="overflow-y:auto;overflow-x: hidden;padding-top:0.3rem;">' +
                    '<div class="col-md-12">' +
                        '<div class="col-md-6" style="height: 100%;">' +
                            '<div class="col-md-12"><b class="text-aqua big-title">基本信息</b></div>' +
                            '<div class="col-md-6 thumb thumbnail1" style="display: none;margin-top: 0.4rem;padding-right: 0;">' +
                                '<div class="prev"><img src="' + basePath + '/images/prev.png"><span></span></div>' +
                                '<ul><li style="height: 3rem;"><img src="' + basePath + '/images/next.png"></li></ul>' +
                                '<div class="next"><img src="' + basePath + '/images/next.png"><span></span></div>' +
                            '</div>' +
                            '<div class="col-md-6" style="white-space: nowrap;">' +
                                '<p></p>' +
                                '<p><a id="' + CLASS + 'asset-name" class="big-title spanTitle" target="_blank">&nbsp;</a></p>' +
                                '<p><span class="text-muted">设备型号：</span><span id="' + CLASS + 'model"></span></p>' +
                                '<p><span class="text-muted">设备科室：</span><span id="' + CLASS + 'department"></span></p>' +
                                '<p><span class="text-muted">异常时间：</span><span id="' + CLASS + 'abnormal-date"></span></p>' +
                            '</div>' +
                        '</div>' +
                        '<div class="col-md-6" style="height:100%;">' +
                            '<div class="col-md-12">' +
                                '<b class="text-aqua big-title">参数信息</b>' +
                                '<label style="margin-left: 0.8rem;"><input type="radio" name="date" value="0" checked>实时</label>' +
                                '<label style="margin-left:0.1rem;"><input type="radio" name="date" value="1">小时</label>' +
                                '<label style="margin-left:0.1rem;"><input type="radio" name="date" value="2">天</label>' +
                                '<label style="margin-left:0.1rem;"><input type="radio" name="date" value="3">月</label>' +
                                '<button type="button" id="' + CLASS + 'look-more" class="btn btn-default" style="position: absolute;top: 0.1rem;right: 0.2rem;line-height: 1.2;">查询全部</button>' +
                            '</div>' +
                            '<div class="col-md-12">' +
                                '<div id="canshu-chart" style="height: 200px;"></div>' +
                            '</div>' +
                        '</div>' +
                    '</div>' +
                '</div>' +
                '<div id="' + CLASS+ 'history" class="box-body">' +
                    '<div class="col-md-12">' +
                        '<div class="col-md-12"><b class="text-aqua col-md-12 big-title">历史信息</b></div>' +
                        '<div class="col-md-12">' +
                                '<div class="col-md-12">' +
                                    '<table class="table table-bordered table-bordered">' +
                                        '<thead>' +
                                            '<th class="text-center">#</th>' +
                                            '<th class="text-center">参数名称</th>' +
                                            '<th class="text-center">参数值</th>' +
                                            '<th class="text-center">报警范围</th>' +
                                            '<th class="text-center">报警等级</th>' +
                                            '<th class="text-center">异常时间</th>' +
                                        '</thead>' +
                                        '<tbody>' +
                                            '<tr><td class="text-center text-primary" colspan="6">无记录</td></tr>' +
                                        '</tbody>' +
                                    '</table>' +
                                '</div>' +
                        '</div>' +
                    '</div>' +
                '</div>' +
                '<div class="box-body">' +
                    '<div class="col-md-12"><form id="' + CLASS + 'submit-form">' +
                        '<div class="col-md-12"><b class="text-aqua col-md-12 big-title">异常信息</b></div>' +
                        '<div class="col-md-12">' +
                            '<div class="col-md-12">' +
                                '<div class="col-md-12" style="line-height: 44px;">' +
                                    '<div class="col-md-2" style="text-align: right;">处理次数：</div>' +
                                    '<div class="col-md-2" id="' + CLASS + 'deal-times"></div>' +
                                    '<div class="col-md-2" style="text-align: right;">最后处理结果：</div>' +
                                    '<div class="col-md-3" id="' + CLASS + 'deal-result"></div>' +
                                '</div>' +
                                '<div id="'+CLASS+'other-parameter" class="col-md-12" style="display: none;line-height: 44px;"><div class="col-md-2" style="text-align: right;">其他异常参数：</div><div class="col-md-10" id="' + CLASS + 'other-abnormal"></div></div>' +
                                '<div class="col-md-12" style="line-height: 44px;"><div class="col-md-2" style="text-align: right;">异常描述：</div><div class="col-md-10" id="' + CLASS + 'abnormal-description"></div></div>' +
                                '<div class="col-md-12"><div class="col-md-2" style="text-align: right;line-height:0.84rem;">处理意见<span style="color:red;"> *</span></div><div class="col-md-8 form-group"><input type="text" name="suggest" class="form-control" id="' + CLASS + 'deal-suggest"></div></div>' +
                                '<div class="col-md-12"><div class="col-md-2" style="text-align: right;line-height:0.84rem;">处理时间<span style="color:red;"> *</span></div><div class="col-md-8 form-group"><input type="text" name="dealdate" class="form-control" id="' + CLASS + 'deal-date"></div></div>' +
                                '<div class="col-md-12"><div class="col-md-2" style="text-align: right;line-height:0.84rem;">处理人<span style="color:red;"> *</span></div><div class="col-md-8 form-group"><input type="text" name="person" class="form-control" id="' + CLASS + 'deal-person"></div></div>' +
                                '<div class="col-md-12"><div class="col-md-2" style="text-align: right;line-height:0.84rem;">处理人电话<span style="color:red;"> *</span></div><div class="col-md-8 form-group"><input type="text" name="phone" class="form-control" id="' + CLASS + 'deal-phone"></div></div>' +
                                '<div class="col-md-12"><div class="col-md-2" style="text-align: right;line-height:0.84rem;">处理结果<span style="color:red;"> *</span></div><div class="col-md-8 form-group"><input type="text" name="results" class="form-control" id="' + CLASS + 'deal-results"></div></div>' +
                                '<div class="col-md-12"><div class="col-md-2" style="text-align: right;line-height:0.84rem;">备注：</div><div class="col-md-8 form-group"><input type="text" class="form-control" id="' + CLASS + 'remark"></div></div>' +
                            '</div>' +
                        '</div>' +
                    '</form></div>' +
                '</div>' +
                '<div class="box-footer text-center" style="padding: 0 1rem;line-height: 0.6rem;text-align: right;">' +
                    '<button type="button" id="' + CLASS + 'deal-bypass" class="btn btn-default cancel" style="display: none;">暂不处理</button>' +
                    '<button type="button" id="' + CLASS + 'deal-submit" class="btn save">' + (isWebsocket ? '合并处理' : '提交处理') +'</button>' +
                    '<button type="button" id="' + CLASS + 'deal-repair" class="btn save">报修处理</button>' +
                '</div>' +
            '</div>' +
                '<style>#'+ CLASS +'modal input[type="radio"]{margin-top: -1px;}</style>');
            model = $('#' + CLASS + 'modal');
            if (isWebsocket) {
                $('#' + CLASS + 'other-parameter').show();
            }
            model.iziModal({
                title: '参数异常',
                headerColor: '#fff',
                rtl: false,
                width: 20 * rem,
                padding: 0,
                radius: 0.4 * rem,
                zindex: 10010,
                focusInput: false,
                group: '',
                history: false,
                autoOpen: false,
                bodyOverflow: true,
                fullscreen: false,
                openFullscreen: false,
                closeOnEscape: false,
                overlay: true,
                overlayClose: false,
                overlayColor: 'rgba(0, 0, 0, 0.4)',
                timeout: false,
                timeoutProgressbar: false,
                pauseOnHover: false,
                timeoutProgressbarColor: 'rgba(255,255,255,0.5)',
                transitionIn: 'comingIn',
                transitionOut: 'comingOut',
                transitionInOverlay: 'fadeIn',
                transitionOutOverlay: 'fadeOut',
                onFullscreen: function(){},
                onResize: function(){},
                onOpening: function(){
                    model.find('#' + CLASS + 'deal-date').datetimepicker({
                        todayHighlight:true,	// 当前时间高亮显示
                        autoclose:true,
                        endDate:new Date(),		// 选择日期不能超过当前日期
                        todayBtn:true,			// 底部显示今天按钮
                        minuteStep:1,
                        language:'zh-CN',
                        upkeepDate : new Date()
                    }).on('hide', function(e) {
                        $('#' + CLASS + 'submit-form').data('bootstrapValidator')
                            .updateStatus('dealdate', 'NOT_VALIDATED', null)
                            .validateField('dealdate');
                    });
                },
                onOpened: function(){},
                onClosing: function(){},
                onClosed: function(){
                    model.remove();
                }
            });
        }
        model.iziModal('open');
        model.find('.iziModal-button-close').off().click(function (e){
            e.stopPropagation();
            model.iziModal('close');
            if (isWebsocket) {
                messageObjArr[messageObjArr.index].isDoNow = true;
                dealPushMessage();
            }
        });

        // 初始化校验
        $('#' + CLASS + 'submit-form').bootstrapValidator({
            excluded: [':disabled', ':hidden', ':not(:visible)'],
            live: 'enabled',
            message: '非有效值',
            fields: {
                suggest: {
                    validators: {
                        notEmpty: {
                            message: '处理意见不能为空'
                        }
                    }
                },
                dealdate: {
                    validators: {
                        notEmpty: {
                            message: '处理时间不能为空'
                        }
                    }
                },
                person: {
                    validators: {
                        notEmpty: {
                            message: '处理人不能为空'
                        }
                    }
                },
                phone: {
                    validators: {
                        notEmpty: {
                            message: '处理人结果不能为空'
                        },
                        regexp: {
                            regexp:  /^1[3456789]\d{9}$/,
                            message: '联系电话不合格'
                        }
                    }
                },
                results: {
                    validators: {
                        notEmpty: {
                            message: '处理人结果不能为空'
                        }
                    }
                }
            }
        });

        if (!$('#iziModal-repair').length) {
            $('body').append('<div id="iziModal-repair"></div>');
        }
        var repairHistory = model.find('#' + CLASS + 'history');
        var repairHistoryTable = repairHistory.find('table');
        publicAjax(basePath + '/parameterEvent/handleAssetsInfo', 'post', {
            parameterEventId: opts.id,
            parameterId: opts.parameterId,
            createTime: opts.createTime,
            webSocket: isWebsocket
        }, function (data) {
            /* 暂不处理 */
            model.find('#' + CLASS + 'deal-bypass').click(function () {
                publicAjax(basePath + '/parameter/handle', 'post', {
                    parameterEventId: opts.id,
                    status: 38001,
                    webSocket: isWebsocket
                }, function (res) {
                    flavrShowByTime(res.msg, null, 'success', false);
                    model.iziModal('close');
                    if (isWebsocket) {
                        messageObjArr[messageObjArr.index].isDoNow = true;
                        dealPushMessage();
                    }
                });
            });
            /* 合并处理 */
            model.find('#' + CLASS + 'deal-submit').click(function () {
                $('#' + CLASS + 'submit-form').bootstrapValidator('validate');
                if ($('#' + CLASS + 'submit-form').data('bootstrapValidator').isValid()) {
                    publicAjax(basePath + '/parameter/handle', 'post', {
                        parameterEventId: opts.id,
                        status: 38002,
                        webSocket: isWebsocket,
                        createTime: opts.createTime,
                        handleType: 2,
                        handleOpinion: model.find('#' + CLASS + 'deal-suggest').val(),
                        handleTime: model.find('#' + CLASS + 'deal-date').val(),
                        handlePerson: model.find('#' + CLASS + 'deal-person').val(),
                        handlePersonPhone: model.find('#' + CLASS + 'deal-phone').val(),
                        handleResult: model.find('#' + CLASS + 'deal-results').val(),
                        remark: model.find('#' + CLASS + 'deal-remark').val()
                    }, function (res) {
                        if (res.ret === 0) {
                            flavrShowByTime(res.msg, null, 'error', false);
                        } else {
                            flavrShowByTime(res.msg, null, 'success', false);
                            model.iziModal('close');
                            if (isWebsocket) {
                                messageObjArr[messageObjArr.index].isDoNow = true;
                                dealPushMessage();
                            }
                        }
                    });
                }
            });
            /* 报修处理 */
            model.find('#' + CLASS + 'deal-repair').click(function () {
                publicAjax(basePath + '/parameter/handle', 'post', {
                    parameterEventId: opts.id,
                    status: 38004,
                    handleType: 1,
                    webSocket: isWebsocket
                }, function (res) {
                    $("#iziModal-repair").repair({
                        deviceId: data.data.assetsId,
                        deviceName: data.data.assetsName,
                        assetsNo: data.data.assetsNo,
                        parameterEventResultId: res.data,
                        callback: function () {
                            model.iziModal('close');
                            if (isWebsocket) {
                                messageObjArr[messageObjArr.index].isDoNow = true;
                                dealPushMessage();
                            }
                        }
                    });
                });
            });
            /* 设备图片 */
            if (data.data.assetsFile)
                thumb(model.find('.thumbnail1'), data.data.assetsFile);
            // 设备信息
            model.find('#' + CLASS + 'asset-name').text(fixStr(data.data.assetsName)).attr('href', basePath + '/charts/overview/assets/page?deviceId=' + data.data.assetsId);   // 设备名称
            model.find('#' + CLASS + 'model').text(fixStr(data.data.model));  // 型号
            model.find('#' + CLASS + 'department').text(fixStr(data.data.department));  // 科室
            model.find('#' + CLASS + 'abnormal-date').text(fixStr(data.data.createTime));  // 异常时间

            // 历史信息
            var tbody = repairHistoryTable.find("tbody").html('');
            var list = data.data.historyList || [];
            if (list.length){
                repairHistory.slideDown();
                tbody.append("<tr>" +
                    "<td class='text-muted text-center'>1</td>" +
                    "<td class='text-muted text-center'>"+fixStr(list[0].parameterName)+"</td>" +
                    "<td class='text-muted text-center'>"+fixStr(list[0].parameterValue)+"</td>" +
                    "<td class='text-muted text-center'>"+fix2(list[0].numberParameter1) + '-' + fix2(list[0].numberParameter2) + fixStr(list[0].unitDetailName)+"</td>" +
                    "<td class='text-muted text-center'>"+fixStr(list[0].policeLevel)+"</td>" +
                    "<td class='text-muted text-center'>"+fixStr(list[0].createTime)+"</td>" +
                    "</tr>");
                if (list.length > 1) {
                    tbody.append('<tr class="load-more" style="cursor: pointer;"><td class="text-center" style="color:#15b997;text-decoration: underline;" colspan="6">全部显示</td></tr>');
                    var loadMore = tbody.find('.load-more');
                    // 循环追加数据
                    loadMore.click(function () {
                        if (loadMore.hasClass('less')) {
                            loadMore.removeClass('less');
                            loadMore.find('td').html('全部显示');
                            var trs = tbody.find('tr');
                            for(var i = 1; i < trs.length - 1; i++) {
                                trs.eq(i).remove();
                            }
                        } else {
                            loadMore.addClass('less');
                            loadMore.find('td').html('显示一条');
                            for (var i = 1; i < list.length; i++) {
                                loadMore.before("<tr>" +
                                    "<td class='text-muted text-center'>"+(i+1)+"</td>" +
                                    "<td class='text-muted text-center'>"+fixStr(list[i].parameterName)+"</td>" +
                                    "<td class='text-muted text-center'>"+fixStr(list[i].parameterValue)+"</td>" +
                                    "<td class='text-muted text-center'>"+fix2(list[i].numberParameter1) + '-' + fix2(list[i].numberParameter2) + fixStr(list[i].unitDetailName)+"</td>" +
                                    "<td class='text-muted text-center'>"+fixStr(list[i].policeLevel)+"</td>" +
                                    "<td class='text-muted text-center'>"+fixStr(list[i].createTime)+"</td>" +
                                    "</tr>");
                            }
                        }
                    });
                }
            } else {
                repairHistory.slideUp();
            }

            // 异常信息
            model.find('#' + CLASS + 'deal-times').text(fix0(data.data.handleCount) + '次')  // 处理次数
                .addClass(data.data.handleCount > 0 ? 'spanTitle' : '');
            if (data.data.handleCount < 1)
                model.find('#' + CLASS + 'deal-bypass').show();
            model.find('#' + CLASS + 'deal-result').text(fixStr(data.data.lastResult));  // 最后处理结构
            var spanStr = '';
            var a = '';
            if(data.data.numberParameter1 != null && data.data.numberParameter2 != null){
                a = data.data.numberParameter1 + data.data.unitDetailName + '-' + data.data.numberParameter2 + data.data.unitDetailName;
            }else if(data.data.numberParameter1 == null){
                a = data.data.numberOperation2 + data.data.numberParameter2 + data.data.unitDetailName;
            }else if(data.data.numberParameter2 == null){
                a = data.data.numberOperation1 + data.data.numberParameter1 + data.data.unitDetailName;
            }
            spanStr = '当前'+fixStr(data.data.parameterName) + fixStr(data.data.parameterValue) + fixStr(data.data.unitDetailName) + ' , ' + '报警范围' + a + ' , ' + '报警等级' + data.data.policeLevel;
            model.find('#' + CLASS + 'abnormal-description').text(spanStr).prev().text(fixStr(data.data.parameterName) + '异常：');  // 异常信息
            model.find('#' + CLASS + 'other-abnormal').text(fix0(data.data.otherParameterNum) + '个')  // 其他异常参数
                .addClass(data.data.otherParameterNum > 0 ? 'spanTitle' : '').off().click(function () {
                    if (data.data.otherParameterNum > 0 && data.data.otherEventIds) {
                        queryOtherResult(data.data.otherEventIds);
                    }
            });
        });

        /* 缩略图 */
        function thumb(thumbnail2, assetsPhotos) {
            var assetsPhotos = assetsPhotos.split(',');
            if (!assetsPhotos[assetsPhotos.length - 1]) {
                assetsPhotos.pop();
            }
            thumbnail2.find('ul img').attr('src', assetsPhotos[0]).viewer({zIndex:10011});
            var prev = thumbnail2.find('.prev').css('visibility', 'hidden');
            var next = thumbnail2.find('.next').css('visibility', 'hidden');
            var index = 0;
            if (assetsPhotos.length > 1) {
                next.css('visibility', 'visible');
            }
            next.click(function (){
                index++;
                index %= assetsPhotos.length;
                if (index === assetsPhotos.length - 1) {
                    next.css('visibility', 'hidden');
                    prev.css('visibility', 'visible');
                } else if (index > 0) {
                    prev.css('visibility', 'visible');
                }
                thumbnail2.find('ul img').attr('src', assetsPhotos[index]);
            });
            prev.click(function (){
                index--;
                index = index < 0 ? assetsPhotos.length - 1 : index;
                if (index === 0) {
                    prev.css('visibility', 'hidden');
                    next.css('visibility', 'visible');
                } else if (index < assetsPhotos.length - 1) {
                    next.css('visibility', 'hidden');
                }
                thumbnail2.find('ul img').attr('src', assetsPhotos[index]);
            });
            thumbnail2.show();
        }

        // 设置电流电压图
        var option = [{ /* 实时数据 */
            color: ['#1ab9f1', '#59b537'],
            tooltip: {
                trigger: 'axis', axisPointer: {type: 'shadow'}, textStyle: {fontSize: 0.28 * rem},
                formatter: function (params) {
                    var str = params[0].name + '<br/>';
                    for (var i = 0; i < params.length; i++) {
                        str += params[i].seriesName + '：' + params[i].value + params[i].seriesId.split('-')[0] + '<br/>'
                    }
                    return str;
                }
            },
            legend: {x: "center", textStyle: {color: '#AAA', fontSize: 0.28 * rem}, data: []},
            dataZoom: {type: 'inside', xAxisIndex: [0], start: 0, end: 100},
            grid: {top: 0.8 * rem, left: 0, right: 0, bottom: 0, containLabel: true},
            xAxis: {
                type: 'category', data: [],
                axisLabel: {rotate: 30, fontWeight: 100, fontSize: 0.24 * rem, textStyle: {color: '#fff'}},
                nameTextStyle: {color: '#666', fontSize: 0.28 * rem},
                axisLine: {lineStyle: {color: '#666'}},
                axisTick: {lineStyle: {color: '#666'}}
            },
            visualMap: [{
                show: false, dimension: 1, seriesIndex: 0,
                pieces: [{min: 235, color: 'red'}, {max: 198, color: 'red'}, {min: 198, max: 235, color: '#1ab9f1'}]
            }, {
                show: false, seriesIndex: 1,
                pieces: [{min: 2.2, color: 'red'}, {max: 1.8, color: 'red'}, {min: 1.8, max: 2.2, color: '#59b537'}]
            }],
            yAxis: [{
                name: '', type: 'value',
                splitLine: {lineStyle: {type: 'dashed'}},
                axisLabel: {fontSize: 0.28 * rem, textStyle: {color: '#666'}},
                nameTextStyle: {color: '#666', fontSize: 0.28 * rem},
                axisLine: {lineStyle: {color: '#666'}},
                axisTick: {lineStyle: {color: '#666'}}
            }, {
                name: '', type: 'value',
                splitLine: {show: false, lineStyle: {type: 'dashed'}},
                axisLabel: {fontSize: 0.28 * rem, textStyle: {color: '#666'}},
                nameTextStyle: {color: '#666', fontSize: 0.28 * rem},
                axisLine: {lineStyle: {color: '#666'}},
                axisTick: {lineStyle: {color: '#666'}}
            }],
            series: [
                {name: '电压', type: 'line', yAxisIndex: 0, symbol: 'circle', data: []},
                {name: '电流', type: 'line', yAxisIndex: 1, symbol: 'circle',data: []}]
        }, {    /* 月日时图表 */
            color: ['#1ab9f1', '#0094c8', '#a7e2f7', '#59b537', '#1a5f00', '#9ae57e'],
            tooltip: {
                trigger: 'axis', axisPointer: {type: 'shadow'}, textStyle: {fontSize: 0.28 * rem},
                formatter: function (params) {
                    var str = params[0].name + '<br/>';
                    for (var i = 0; i < params.length; i++) {
                        str += params[i].seriesName + '：' + params[i].value + params[i].seriesId.split('-')[0] + '<br/>'
                    }
                    return str;
                }
            },
            legend: {x: "center", textStyle: {color: '#AAA', fontSize: 0.20 * rem}, data: [], selected: {}},
            dataZoom: {type: 'inside', xAxisIndex: [0], start: 0, end: 100},
            grid: {top: 0.8 * rem, left: 0, right: 0, bottom: 0, containLabel: true},
            xAxis: {
                type: 'category', data: [],
                axisLabel: {rotate: 30, fontWeight: 100, fontSize: 0.24 * rem, textStyle: {color: '#fff'}},
                nameTextStyle: {color: '#666', fontSize: 0.28 * rem},
                axisLine: {lineStyle: {color: '#666'}},
                axisTick: {lineStyle: {color: '#666'}}
            },
            visualMap: [{
                show: false, seriesIndex: 0,
                pieces: [{min: 235, color: 'red'}, {max: 198, color: 'red'}, {min: 198, max: 235, color: '#1ab9f1'}]
            }, {
                show: false, seriesIndex: 1,
                pieces: [{min: 235, color: 'red'}, {max: 198, color: 'red'}, {min: 198, max: 235, color: '#0094c8'}]
            }, {
                show: false, seriesIndex: 2,
                pieces: [{min: 235, color: 'red'}, {max: 198, color: 'red'}, {min: 198, max: 235, color: '#a7e2f7'}]
            },{
                show: false, seriesIndex: 3,
                pieces: [{min: 235, color: 'red'}, {max: 198, color: 'red'}, {min: 1.8, max: 2.2, color: '#59b537'}]
            },{
                show: false, seriesIndex: 4,
                pieces: [{min: 235, color: 'red'}, {max: 198, color: 'red'}, {min: 1.8, max: 2.2, color: '#1a5f00'}]
            },{
                show: false, seriesIndex: 5,
                pieces: [{min: 235, color: 'red'}, {max: 198, color: 'red'}, {min: 1.8, max: 2.2, color: '#9ae57e'}]
            }],
            yAxis: [{
                name: '', type: 'value',
                splitLine: {lineStyle: {type: 'dashed'}},
                axisLabel: {fontSize: 0.28 * rem, textStyle: {color: '#666'}},
                nameTextStyle: {color: '#666', fontSize: 0.28 * rem},
                axisLine: {lineStyle: {color: '#666'}},
                axisTick: {lineStyle: {color: '#666'}}
            }, {
                name: '', type: 'value',
                splitLine: {show: false, lineStyle: {type: 'dashed'}},
                axisLabel: {fontSize: 0.28 * rem, textStyle: {color: '#666'}},
                nameTextStyle: {color: '#666', fontSize: 0.28 * rem},
                axisLine: {lineStyle: {color: '#666'}},
                axisTick: {lineStyle: {color: '#666'}}
            }],
            series: [
                {name: '电压平均值', type: 'line', yAxisIndex: 0, symbol: 'circle', data: []},
                {name: '电压最大值', type: 'line', yAxisIndex: 0, symbol: 'circle', data: []},
                {name: '电压最小值', type: 'line', yAxisIndex: 0, symbol: 'circle', data: []},
                {name: '电流平均值', type: 'line', yAxisIndex: 1, symbol: 'circle',data: []},
                {name: '电流最大值', type: 'line', yAxisIndex: 1, symbol: 'circle',data: []},
                {name: '电流最小值', type: 'line', yAxisIndex: 1, symbol: 'circle',data: []}]
        }];
        var chart = echarts.init($('#canshu-chart')[0]);
        queryCharts(0);
        /* 查询图表信息 */
        function queryCharts(type) {
            var url = type > 0 ? '/parameter/dimension' : '/parameter/live';
            publicAjax(basePath + url, 'post', {
                id: opts.id,
                assetsId: opts.assetsId,
                parameterName: opts.parameterName,
                createTime: opts.createTime,
                type: type
            }, function (data) {
                var list = (data.data.list || []).sort(function (a, b) {
                        return a.name.indexOf('电流') !== -1 || a.name.indexOf('湿度') !== -1;
                    }),
                    parameterList;
                var legend = [],
                    xAxis,
                    series = [];
                if (type > 0) {
                    for (var i = 0; i < list.length; i++) {
                        legend.push(fixStr(list[i].name) + '平均值');
                        legend.push(fixStr(list[i].name) + '最大值');
                        legend.push(fixStr(list[i].name) + '最小值');
                        option[1].legend.selected[fixStr(list[i].name) + '最大值'] = false;
                        option[1].legend.selected[fixStr(list[i].name) + '最小值'] = false;
                        option[1].yAxis[i].name = fixStr(list[i].unitText);
                        option[1].series[i * 3].id = fixStr(list[i].unitText) + '-' + i * 3;
                        option[1].series[i * 3 + 1].id = fixStr(list[i].unitText) + '-' + i * 3 + 1;
                        option[1].series[i * 3 + 2].id = fixStr(list[i].unitText) + '-' + i * 3 + 2;
                        option[1].series[i * 3].name = fixStr(list[i].name) + '平均值';
                        option[1].series[i * 3 + 1].name = fixStr(list[i].name) + '最大值';
                        option[1].series[i * 3 + 2].name = fixStr(list[i].name) + '最小值';
                        parameterList = list[i].parameterDimensionList || [];
                        xAxis = [];
                        series[i * 3] = [];
                        series[i * 3 + 1] = [];
                        series[i * 3 + 2] = [];
                        for (var k = 0; k < parameterList.length; k++) {
                            xAxis.push(fixStr(parameterList[k].time));
                            series[i * 3].push(fix2(parameterList[k].avgValue));
                            series[i * 3 + 1].push(fix2(parameterList[k].maxValue));
                            series[i * 3 + 2].push(fix2(parameterList[k].minValue));
                        }
                        option[1].xAxis.data = xAxis;
                        option[1].series[i * 3].data = series[i * 3];
                        option[1].series[i * 3 + 1].data = series[i * 3 + 1];
                        option[1].series[i * 3 + 2].data = series[i * 3 + 2];

                        option[1].visualMap[i * 3].pieces[0].min = parseFloat(fix2(list[i].maxLevelValue));
                        option[1].visualMap[i * 3].pieces[1].max = parseFloat(fix2(list[i].minLevelValue));
                        option[1].visualMap[i * 3 + 1].pieces[0].min = parseFloat(fix2(list[i].maxLevelValue));
                        option[1].visualMap[i * 3 + 1].pieces[1].max = parseFloat(fix2(list[i].minLevelValue));
                        option[1].visualMap[i * 3 + 2].pieces[0].min = parseFloat(fix2(list[i].maxLevelValue));
                        option[1].visualMap[i * 3 + 2].pieces[1].max = parseFloat(fix2(list[i].minLevelValue));
                        option[1].visualMap[i * 3].pieces[2].min = parseFloat(fix2(list[i].minLevelValue));
                        option[1].visualMap[i * 3].pieces[2].max = parseFloat(fix2(list[i].maxLevelValue));
                        option[1].visualMap[i * 3 + 1].pieces[2].min = parseFloat(fix2(list[i].minLevelValue));
                        option[1].visualMap[i * 3 + 1].pieces[2].max = parseFloat(fix2(list[i].maxLevelValue));
                        option[1].visualMap[i * 3 + 2].pieces[2].min = parseFloat(fix2(list[i].minLevelValue));
                        option[1].visualMap[i * 3 + 2].pieces[2].max = parseFloat(fix2(list[i].maxLevelValue));
                    }
                    option[1].legend.data = legend;
                    chart.clear();
                    chart.setOption(option[1]);
                } else {
                    for (var i = 0; i < list.length; i++) {
                        legend.push(fixStr(list[i].name));
                        option[0].yAxis[i].name = fixStr(list[i].unitText);
                        option[0].series[i].id = fixStr(list[i].unitText) + '-' + i;
                        option[0].series[i].name = fixStr(list[i].name);
                        parameterList = list[i].parameterDimensionList || [];
                        xAxis = [];
                        series[i] = [];
                        for (var k = 0; k < parameterList.length; k++) {
                            xAxis.push(fixStr(parameterList[k].time));
                            series[i].push(fix2(parameterList[k].liveValue));
                        }
                        option[0].xAxis.data = xAxis;
                        option[0].series[i].data = series[i];
                        option[0].visualMap[i].pieces[0].min = parseFloat(fix2(list[i].maxLevelValue));
                        option[0].visualMap[i].pieces[1].max = parseFloat(fix2(list[i].minLevelValue));
                        option[0].visualMap[i].pieces[2].min = parseFloat(fix2(list[i].minLevelValue));
                        option[0].visualMap[i].pieces[2].max = parseFloat(fix2(list[i].maxLevelValue));
                    }
                    option[0].legend.data = legend;
                    chart.clear();
                    chart.setOption(option[0]);
                }
            });
        }

        model.find('input[name="date"]').click(function () {
            var value = $(this).val();
            queryCharts(value);
        });

        //查看更多
        model.find('#' + CLASS + 'look-more').click(LookMore);
        function LookMore() {
            morePrameterLiat.iziModal("open");
            Current_Parameter_List(opts.assetsId);
        }

        //实时参数列表
        function Current_Parameter_List(id) {
            $.ajax({
                type: "POST",
                url: basePath+"/parameterEvent/queryAll",
                dataType: "json",
                data:{
                    assetsId:id,
                    parameterName:morePrameterLiat.find('#Parameter_Name_Modal').val(),
                    startTime:morePrameterLiat.find('#Start_Time').val(),
                    endTime:morePrameterLiat.find('#End_Time').val()
                },
                success: function(data){
                    if(data.ret == 200){
                        var list = data.data;
                        var str = '';
                        $.each(list,function (key,val) {
                            str += "<tr><td class='text-center text-muted td-width'>"+(val.parameterName == null ? '' : val.parameterName)+"</td>\
                                      <td class='text-center text-muted td-width'>"+(val.parameterValue + val.unitDetail)+"</td>\
                                      <td class='text-center text-muted td-width'>"+(val.createTime == null ? '' : val.createTime)+"</td>\
                                      <td class='text-center text-muted td-width'>"+(val.parameterLevel == null ? '' : val.parameterLevel)+"</td>\
                                      </tr>"
                        });
                        morePrameterLiat.find('#addParameter_table tbody').html(str);
                    }
                }
            });
        }
        
        var morePrameterLiat = $('<div id="Current_Parameter_List" class="score" style="display: none;">' +
            '    <div class="form-group col-md-12" style="margin-top: 20px">' +
            '        <div class="col-md-3">' +
            '            <input class="form-control" name="Parameter_Name_Modal" id="Parameter_Name_Modal" placeholder="参数名称">' +
            '        </div>' +
            '        <div class="col-md-3">' +
            '            <input class="form-control" name="Start_Time" id="Start_Time" placeholder="开始时间">' +
            '        </div>' +
            '        <div class="col-md-3">' +
            '            <input class="form-control" name="End_Time" id="End_Time" placeholder="结束时间">' +
            '        </div>' +
            '        <div class="col-md-3">' +
            '            <button id="search_parameter" class="btn btn-info btn-sm pull-right"  title="查询" style="margin-right:5px">' +
            '                <i class="fa fa-search"></i>' +
            '            </button>' +
            '        </div>' +
            '    </div>' +
            '    <div class="box-body col-md-12">' +
            '        <div class="form-group col-md-12">' +
            '            <table class="table table-bordered table-striped table-hover" id="addParameter_table">' +
            '                <thead>' +
            '                <tr class="info">' +
            '                    <th class="text-muted text-center">' +
            '                        <span>参数名称</span>' +
            '                    </th>' +
            '                    <th class="text-muted text-center">' +
            '                        <span>参数值</span>' +
            '                    </th>' +
            '                    <th class="text-muted text-center">' +
            '                        <span>采集时间</span>' +
            '                    </th>' +
            '                    <th class="text-muted text-center">' +
            '                        <span>参数级别</span>' +
            '                    </th>' +
            '                </tr>' +
            '                </thead>' +
            '                <tbody></tbody>' +
            '            </table>' +
            '        </div>' +
            '    </div>' +
            '    <div class="box-footer text-right">' +
            '        <button data-iziModal-close class="btn btn-default cancel">关闭</button>' +
            '    </div>' +
            '</div>').appendTo($('body'));

        morePrameterLiat.iziModal({
            title:"实时参数列表",
            rtl: false,
            focusInput: false,
            group: '',
            loop: false,
            history: false,
            restoreDefaultContent: false,
            autoOpen: false, // Boolean, Number
            bodyOverflow: true,
            overlayClose: false,
            headerColor: '#fff',
            iconColor: '#4c4c4c',
            width: 16 * rem,
            radius: 0.4 * rem,
            zindex: 10016,
            overlayColor: 'rgba(0, 0, 0, 0.4)',
            onOpening: function(){
                morePrameterLiat.find("#Start_Time").datetimepicker({
                    autoclose: true,
                    todayHighlight:true,
                    language:'zh-CN',
                    forceParse:true,
                    format:'yyyy-mm-dd',
                    minView:2,
                    todayBtn:true
                });
                morePrameterLiat.find("#End_Time").datetimepicker({
                    autoclose: true,
                    todayHighlight:true,
                    language:'zh-CN',
                    forceParse:true,
                    format:'yyyy-mm-dd',
                    minView:2,
                    todayBtn:true
                });
                morePrameterLiat.find('#search_parameter').off().click(function () {
                    Current_Parameter_List(opts.assetsId)
                });
            },
            onOpened: function(){},
            onClosing: function(){
                morePrameterLiat.addClass('score');
            },
            onClosed: function(){
                morePrameterLiat.addClass('score');
            }
        });

        var disposeResult = $('<div id="Dispose_Result" class="score" style="display: none;">' +
            '    <div class="box-body">' +
            '    </div>' +
            '    <div class="box-footer text-right">' +
            '        <button data-iziModal-close class="btn btn-default cancel">关闭</button>' +
            '    </div>' +
            '</div>').appendTo($('body'));
        disposeResult.iziModal({
            title: '处理结果',
            rtl: false,
            focusInput: false,
            group: '',
            loop: false,
            history: false,
            restoreDefaultContent: false,
            autoOpen: false, // Boolean, Number
            bodyOverflow: true,
            overlayClose: false,
            headerColor: '#fff',
            iconColor: '#4c4c4c',
            width: 16 * rem,
            radius: 0.4 * rem,
            zindex: 10019,
            overlayColor: 'rgba(0, 0, 0, 0.4)',
            onFullscreen: function(){},
            onResize: function(){},
            onOpening: function(){},
            onOpened: function(){},
            onClosing: function(){
                disposeResult.addClass('score');
            },
            onClosed: function(){
                disposeResult.find('.box-body').html('');
                disposeResult.addClass('score');
            }
        });

        model.find('#' + CLASS + 'deal-times').click(function () {
            if (parseFloat($(this).text()) > 0) {
                Dispose_Result(opts.id);
            }
        });
        //处理结果查看
        function Dispose_Result(id) {
            disposeResult.iziModal("open");
            $.ajax({
                type : "post",
                url : basePath+'/parameterEvent/info',
                data :{ parameterEventId: id},
                dataType: "json",
                success : function(data){
                    if(data.ret == 200){
                        var list = data.data;
                        var str = '';
                        $.each(list,function (key,val) {
                            str += '<div class="col-md-12">\
                                <div class="form-group col-md-6">\
                                    <label class="col-md-6 text-right">处理时间</label>\
                                    <div class="col-md-6 text-left">\
                                        <span class="detail-param-name">'+fixStr(val.handleTime)+'</span>\
                                    </div>\
                                </div>\
                                <div class="form-group col-md-6">\
                                    <label class="col-md-6 text-right">处理类型</label>\
                                    <div class="col-md-6 text-left">\
                                        <span class="basics-param-name">'+(val.handleType == 1 ? '保修处理':'一般处理')+'</span>\
                                    </div>\
                                </div>\
                                <div class="form-group col-md-6">\
                                    <label class="col-md-6 text-right">处理意见</label>\
                                    <div class="col-md-6 text-left">\
                                        <span class="detail-param-name">'+fixStr(val.handleOpinion)+'</span>\
                                    </div>\
                                </div>\
                                <div class="form-group col-md-6">\
                                    <label class="col-md-6 text-right">处理人</label>\
                                    <div class="col-md-6 text-left">\
                                        <span class="basics-param-name">'+fixStr(val.handlePerson)+'</span>\
                                    </div>\
                                </div>\
                                <div class="form-group col-md-6">\
                                    <label class="col-md-6 text-right">处理电话</label>\
                                    <div class="col-md-6 text-left">\
                                        <span class="detail-param-name">'+fixStr(val.handlePersonPhone)+'</span>\
                                    </div>\
                                </div>\
                                <div class="form-group col-md-6">\
                                    <label class="col-md-6 text-right">处理结果</label>\
                                    <div class="col-md-6 text-left">\
                                        <span class="basics-param-name">'+fixStr(val.handleResult)+'</span>\
                                    </div>\
                                </div>\
                                <div class="form-group col-md-6">\
                                    <label class="col-md-6 text-right">上报人</label>\
                                    <div class="col-md-6 text-left">\
                                        <span class="basics-param-name">'+fixStr(val.handlePerson)+'</span>\
                                    </div>\
                                </div>\
                                <div class="form-group col-md-6">\
                                    <label class="col-md-6 text-right">上报时间</label>\
                                    <div class="col-md-6 text-left">\
                                        <span class="basics-param-name">'+fixStr(val.handleResult)+'</span>\
                                    </div>\
                                </div>\
                                <div class="form-group col-md-6" style="border-bottom: 1px solid #ccc">\
                                    <label class="col-md-6 text-right">备注</label>\
                                    <div class="col-md-6 text-left">\
                                        <span class="basics-param-name">'+fixStr(val.remark)+'</span>\
                                    </div>\
                                </div>\
                                <div class="form-group col-md-6" style="border-bottom: 1px solid #ccc">\
                                    <label class="col-md-6 text-right">报修单号</label>\
                                    <div class="col-md-6 text-left">\
                                        <span class="basics-param-name text-aqua" onclick="javascript:window.open('+basePath+'/charts/assets/repair/page?id='+val.repairId+');">'+fixStr(val.repairNumber)+'</span>\
                                    </div>\
                                </div>\
                            </div>'
                        });
                        disposeResult.find('.box-body').css('margin-top', 20).html(str);
                    }
                }
            })
        }

        var otherResult = $('<div id="other-sesult" class="score" style="display: none;">' +
            '    <div class="box-body">' +
            '       <table class="table table-bordered table-striped">' +
            '           <thead>' +
            '               <th class="text-center">#</th>' +
            '               <th class="text-center">参数名称</th>' +
            '               <th class="text-center">参数值</th>' +
            '               <th class="text-center">报警范围</th>' +
            '               <th class="text-center">报警等级</th>' +
            '               <th class="text-center">异常时间</th>' +
            '           </thead>' +
            '           <tbody></tbody>' +
            '       </table>' +
            '    </div>' +
            '    <div class="box-footer text-right">' +
            '        <button data-iziModal-close class="btn btn-default cancel">关闭</button>' +
            '    </div>' +
            '</div>').appendTo($('body'));
        otherResult.iziModal({
            title: '其他异常参数',
            rtl: false,
            focusInput: false,
            group: '',
            loop: false,
            history: false,
            restoreDefaultContent: false,
            autoOpen: false, // Boolean, Number
            bodyOverflow: true,
            overlayClose: false,
            headerColor: '#fff',
            iconColor: '#4c4c4c',
            width: 16 * rem,
            radius: 0.4 * rem,
            zindex: 10019,
            overlayColor: 'rgba(0, 0, 0, 0.4)',
            onFullscreen: function(){},
            onResize: function(){},
            onOpening: function(){},
            onOpened: function(){},
            onClosing: function(){
                otherResult.addClass('score');
            },
            onClosed: function(){
                otherResult.find('.box-body').html('');
                otherResult.addClass('score');
            }
        });
        //处理结果查看
        function queryOtherResult(id) {
            otherResult.iziModal("open");
            $.ajax({
                type : "post",
                url : basePath+'/parameter/other',
                data :{ otherEventIds: id},
                dataType: "json",
                success : function(data){
                    if(data.ret == 1){
                        var list = data.data.list || [];
                        var str = '';
                        for (var i = 0; i < list.length; i++) {
                            str += '<tr>' +
                                '<td class="text-center">' + (i + 1) + '</td>' +
                                '<td class="text-center">' + fixStr(list[i].parameterName) + '</td>' +
                                '<td class="text-center">' + fixStr(list[i].parameterValue) + '</td>' +
                                '<td class="text-center">' + fix2(list[i].numberParameter1) + '-' + fix2(list[i].numberParameter2) + fixStr(list[i].unitDetailName) + '</td>' +
                                '<td class="text-center">' + fixStr(list[i].policeLevel) + '</td>' +
                                '<td class="text-center">' + fixStr(list[i].createTime) + '</td>' +
                                '</tr>';
                        }
                        otherResult.find('.box-body').css('margin-top', 20).find('tbody').html(str);
                    } else {
                        flavrShowByTime(data.msg, null, 'error', false);
                    }
                }
            })
        }
    };
})(jQuery);
